package org.dizena.modules.master.web;

import org.dizena.base.avo.req.JqGridReq;
import org.dizena.base.avo.resp.JqGridResp;
import org.dizena.modules.master.bean.User;
import org.dizena.modules.master.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("master/user")
public class MasterUserController
{

    @Resource
    private UserService userService;

    @GetMapping("list")
    public String list(Model m)
    {
        String initData = userService.initData();
        m.addAttribute("initData", initData);
        return "master/user/list";
    }

    @PostMapping("list")
    @ResponseBody
    public JqGridResp<User> list(JqGridReq req)
    {
        return userService.list(req);
    }

    @PostMapping("crud")
    @ResponseBody
    public String crud(String oper, User user)
    {
        return userService.crud(oper, user);
    }

    @GetMapping("lock/{id}")
    public String lock(@PathVariable("id") String id)
    {
        userService.lockUser(id);
        return "redirect:/master/user/list";
    }

}
